<?php
//namespace escouting\group_calendar;

class Week {
	public function __construct ( Day $reference_day = null ) {
		if ( is_null ( $reference_day ) )
			$reference_day = new Day ( new DateTime () );
		$this->init ( $reference_day );
	}

	public $days_of_week;  //Array of seven Day objects
	public $base_day;      //Day object
	
	private function init( Day $reference_day ) {
		$this->base_day = $reference_day;
		$dow = $this->base_day->get_day_of_week_number ( );
		if ( $dow > 1 )
			$this->base_day->base_date->sub ( new DateInterval ( "P" . ( $dow - 1 ) . "D" ) );
		$this->days_of_week = array ( $this->base_day,                                         // Monday
									$this->base_day->get_relative_date ( new DateInterval ( "P1D" ) ),  // Tuesday
									$this->base_day->get_relative_date ( new DateInterval ( "P2D" ) ),  // Wednesday
									$this->base_day->get_relative_date ( new DateInterval ( "P3D" ) ),  // Thursday
									$this->base_day->get_relative_date ( new DateInterval ( "P4D" ) ),  // Friday
									$this->base_day->get_relative_date ( new DateInterval ( "P5D" ) ),  // Saturday
									$this->base_day->get_relative_date ( new DateInterval ( "P6D" ) )   // Sunday
								);
	}
	
	public function __toString ( ) {
		return "Week of " . $this->base_day->format ( "F j, Y");
	}	
}